package com.harzone.commons.search.domain;

import java.util.ArrayList;
import java.util.List;

import com.harzone.commons.search.utils.SearchUtil;

/**
 * 方法列
 * @author ls
 * 2014年11月21日下午2:33:25
 */
public class MethodField extends Field implements Cloneable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//参数
	private List<KeyValue> params = new ArrayList<KeyValue>();
	//条件
	private String option;

	public MethodField(AFunctions af, String option, String alias) {
		super(af.getName(), alias);
		this.option = option;
		if (alias==null||alias.trim().length()==0) {
			this.setAlias(this.toString());
		}
	}

	public MethodField(AFunctions af) {
		this(af, null,null);
		this.addParam("*");
	}
	
	public MethodField addParam(Object value){
		this.params.add(new KeyValue(value));
		return this;
	}

	public MethodField addParam(String key,Object value){
		this.params.add(new KeyValue(key, value));
		return this;
	} 
	
	public List<KeyValue> getParams() {
		return params;
	}

	@Override
	public String toString() {
		if (option != null) {
			return this.name + "(" + option + " " + SearchUtil.joiner(params, ",") + ")";
		}
		return this.name + "(" + SearchUtil.joiner(params, ",") + ")";
	}
	
	/**
	 * 显示的列名
	 * @author ls
	 * 2014年11月25日上午10:31:57 
	 * @return
	 */
	@Override
	public String getShowName(){
		return this.getAlias();
	}

	public String getOption() {
		return option;
	}

	public void setOption(String option) {
		this.option = option;
	}

}
